package mbp.gui.frames;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import mbp.agents.MbpManagerAgent;
import mbp.core.CounterOffer;
import mbp.gui.panels.COfferDetailsPanel;
import mbp.gui.panels.OfferInfoPanel;

import javax.swing.JButton;

public class COfferEditor extends JFrame implements ActionListener
{

	private JPanel contentPane;
	private OfferInfoPanel offerInfoPanel;
	private COfferDetailsPanel cofferDetailsPanel;
	private CounterOffer counterOffer;
	private MbpManagerAgent manager;
	private String agentName;
	public JButton btnSend;

	/**
	 * Create the frame.
	 */
	public COfferEditor(CounterOffer counterOffer, MbpManagerAgent manager, String agentName)
	{
		this.counterOffer = counterOffer;
		this.manager = manager;
		this.agentName = agentName;
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 673, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(null);
		setContentPane(contentPane);
		
//		offerInfoPanel = new OfferInfoPanel();
//		offerInfoPanel.setBounds(10, 11, 646, 122);
//		offerInfoPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Offer info", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
//		contentPane.add(offerInfoPanel);
//		offerInfoPanel.loadOfferInfo(counterOffer.getOffer());
		
		cofferDetailsPanel = new COfferDetailsPanel();
		cofferDetailsPanel.setBounds(10, 11, 646, 410);
		cofferDetailsPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Counteroffer details", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		contentPane.add(cofferDetailsPanel);
		
		btnSend = new JButton("Send");
		btnSend.setBounds(566, 432, 89, 23);
		contentPane.add(btnSend);
		btnSend.addActionListener(this);
		
		cofferDetailsPanel.loadCOffer(counterOffer);
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
		if(e.getSource() == btnSend)
		{
			manager.SendCounterOffer(counterOffer, agentName);
		}
		// TODO Auto-generated method stub
		
	}
}
